﻿using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using ExtendedMvc.Common.EntityFramework;

namespace ExtendedMvc.WebTest.Model.Entities {
	[MetadataType(typeof(UserMetadata))]
	partial class User : ILogicalEntity {
		public PasswordStatus PasswordStatus {
			get { return (PasswordStatus)PasswordStatusValue; }
			set { PasswordStatusValue = (byte)value; }
		}

		//public ICollection<IGroup> Groups {
		//    get { return (ICollection<IGroup>)GroupList.Cast<IGroup>(); }
		//    set { GroupList = (ICollection<Group>)value.OfType<Group>(); }
		//}
	}

	public class UserMetadata : EntityMetadata {
		[Display(Name = "Login", AutoGenerateFilter = true)]
		[Required(AllowEmptyStrings = false, ErrorMessage = "Login is required.")]
		[DisplayName("Login")]
		public object Login { get; set; }

		[Display(Name = "Password", AutoGenerateFilter = true)]
		[DataType(DataType.Password)]
		[DisplayName("Password")]
		public object Password { get; set; }

		[Display(Name = "Is Blocked", AutoGenerateFilter = true)]
		[DefaultValue(false)]
		[DisplayName("Is Blocked")]
		public object IsBlocked { get; set; }

		[Display(Name = "Last Password Change", AutoGenerateFilter = false)]
		[ReadOnly(true)]
		[DisplayName("Last Password Change")]
		public object LastPasswordChange { get; set; }

		[ScaffoldColumn(false)]
		public object PasswordStatusValue { get; set; }

		[Display(Name = "Password Status", AutoGenerateFilter = false)]
		[EnumDataType(typeof(PasswordStatus), ErrorMessage = "Not valid password status value.")]
		[Required(AllowEmptyStrings = false, ErrorMessage = "Password status is required.")]
		[DefaultValue(PasswordStatus.Valid)]
		[DisplayName("Password Status")]
		public PasswordStatus PasswordStatus { get; set; }

		//[ScaffoldColumn(false)]
		//public object GroupList { get; set; }

		//[Display(Name = "Groups", AutoGenerateFilter = false)]
		//[DisplayName("Groups")]
		//public object Groups { get; set; }
	}
}
